package com.fwj.common.web;

import com.alibaba.fastjson.JSONObject;
import com.fwj.common.api.MailService;
import com.fwj.core.common.annotation.LoginUser;
import com.fwj.core.common.model.Mail;
import com.fwj.core.common.model.ResponseDTO;
import com.fwj.user.entity.user.UserBaseInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: fwj
 * @Data: 2022/5/3 4:24
 * @Version 1.0
 * @Description:
 */

@RestController
@RequestMapping("/mail")
public class MailController {

    //添加日志工厂
    private static final Logger LOGGER = LoggerFactory.getLogger(MailController.class);

    @Autowired
    private MailService mailService;

    @PostMapping("/sendMail")
    public ResponseDTO sendMail(@RequestBody JSONObject jsonObject, @LoginUser UserBaseInfo userbaseInfo){
        try {
            Mail mail = JSONObject.parseObject(jsonObject.toJSONString(),Mail.class);
            return mailService.sendMail(mail);
        } catch (Exception e) {
            LOGGER.error(e.toString());
            return new ResponseDTO<>().fail();
        }
    }

}
